<?php
// +----------------------------------------------------------------------
// | 知识星球[基于ThinkPHP5开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2019 abcblockchain.io
// +----------------------------------------------------------------------
// | 后台管理使用了HisiPHP
// +----------------------------------------------------------------------
// | Author: abcblockchain.io
// +----------------------------------------------------------------------
namespace app\common\model;

use think\Model;

/**
 * 星球分类模型
 * @package app\common\model
 */
class GroupCategories extends Model
{
    // 定义时间戳字段名
    protected $createTime = 'ctime';
    protected $updateTime = false;

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    /**
     * 获取分类
     * @author
     * @return array|false|\PDOStatement|string|\think\Collection
     */
    function getList(){
        $map['status'] = 1;
        $map['disabled'] = 1;
        $cataList = $this->where($map)->field('id,name')->order('sort asc')->select();
        return $cataList ? $cataList : array();
    }


    /**
     * 获取所有分类(下拉列)
     * @param int $id 选中的ID
     * @author
     * @return string
     */
    public function getOption()
    {
        $map['status'] = 1;
        $map['disabled'] = 1;
        $rows = $this->where($map)->field('id,name')->order('sort asc')->select();
        $str = '';
        foreach ($rows as $k => $v) {
            $str .= '<option value="'.$v['id'].'">'.$v['name'].'</option>';
        }
        return $str;
    }

}
